//
//  ZXDatePickerController.m
//  qianke
//
//  Created by ZX on 2017/6/30.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXDatePickerController.h"

@interface ZXDatePickerController ()
@property(nonatomic,strong)UIDatePicker *myDatePicker;
/*date*/
@property(strong ,nonatomic)NSDate*date;
@end

@implementation ZXDatePickerController
@synthesize myDatePicker;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = baseBackgroundColor;
    self.myDatePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 80, ScreenWidth, 216)];
    [self.myDatePicker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:myDatePicker];
    NSLocale * locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
    self.myDatePicker.locale = locale;
    UIButton * surebutton = [[UIButton alloc]init];
    surebutton.frame = CGRectMake(0, ScreenHeight-50, ScreenWidth, 50);
    surebutton.backgroundColor = baseBlueColor;
    [surebutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [surebutton setTitle:@"确定" forState:UIControlStateNormal];
    [self.view addSubview:surebutton];
    [surebutton addTarget:self action:@selector(sureClick:) forControlEvents:UIControlEventTouchUpInside];
    NSDate *theDate = myDatePicker.date;
    NSLog(@"the date picked is: %@",[theDate descriptionWithLocale:locale]);
    if (_getDate) {   // 代码块属性不为空
//        _getDate(date);
    }
    // Do any additional setup after loading the view.
}
-(void)dateChange:(id)sender{
    _date = myDatePicker.date;
    NSLog(@"%@",_date);
    NSLocale * locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];

    NSLog(@"%@",[_date descriptionWithLocale:locale]);
}
-(void)sureClick:(id)sender{
    NSLocale * locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
    if (_date) {
        if (_getDate) {   // 代码块属性不为空
            _getDate([_date descriptionWithLocale:locale]);
            _getDate2(_date);
        }
    }else{
        NSDate *theDate = myDatePicker.date;
        if (_getDate) {   // 代码块属性不为空
            _getDate([theDate descriptionWithLocale:locale]);
            _getDate2(theDate);
        }
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
